package samsung.entities;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import samsung.other.CountryArea;

/**
 * Class describe country entity.
 *
 * @author Vitaliy Muzalevskiy
 */
public class Country {
    
    public static final int NAME_MAX_LENGTH = 25;
    private final CountryArea countryArea;
    private final String name;
    private List<City> cities = new ArrayList<City>();
    private boolean finish;
    private int lifeCounter;

    public Country(CountryArea countryArea, String name) {
        this.countryArea = countryArea;
        this.name = name;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + Objects.hashCode(this.countryArea);
        hash = 37 * hash + Objects.hashCode(this.name);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Country other = (Country) obj;
        if (!Objects.equals(this.countryArea, other.countryArea)) {
            return false;
        }
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        return true;
    }

    public CountryArea getCountryArea() {
        return countryArea;
    }

    public String getName() {
        return name;
    }
    
    /**
     * Method add new city to a city list of current country.
     *
     * @param city
     */
    public void addCity(City city){
        cities.add(city);
    }
    
    /**
     * @return value of dissemination iterations that country already make.
     */
    public int getLifeCounter() {
        return lifeCounter;
    }    
    
    /**
     * Method increase dissemination counter of current country.
     */
    public void increaseLifeCounter(){
        lifeCounter++;
    }
       
    /**
     * @return list of country cities.
     */
    public List<City> getCities(){ 
        List<City> result = new ArrayList<City>(cities);
        return result;
    }
    
    public boolean isFinish(){
        return finish;
    }
    
    /**
     * Method check if current country cities already end dissemination of all types
     * types of coins, and set finish marker if it does.
     *
     * @return <code>true</code> if all country cities already have all types 
     *      of coins.
     */
    public boolean finishDissemination(){
        for(City city: cities){
            if(!city.isFinish()){
                return false;
            }
        }
        finish = true;
        return true;
    }

    @Override
    public String toString() {
        return "Country{" + "countryArea=" + countryArea + ", name=" + name + '}';
    }
       
}
